//
//  MYDynamicCommentBaseVC.m
//  MuYing
//
//  Created by tbb on 2019/7/24.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "MYDynamicCommentBaseVC.h"
#import "MYDynamicCommentCell.h"
@interface MYDynamicCommentBaseVC ()<QMUITextViewDelegate,QMUIKeyboardManagerDelegate>
//@property (nonatomic, strong) MYDynamicCommentBottonView * bottonView;
@property(nonatomic, strong) QMUITextView *textView;
@property(nonatomic, strong) QMUIKeyboardManager *keyboardManager;
@end

@implementation MYDynamicCommentBaseVC

- (void)viewDidLoad {
    [super viewDidLoad];
}

-(void)setupView {
    [super setupView];
    self.listTableView.frame = CGRectMake(0, 0, kYQPScreenWidth, kYQPScreenHeight-Height_NavBar-kHeight_Botton_SafeArea-50);
    kYQREGISTERTABLEVIEWNIBCELL(@"MYDynamicCommentCell")
    
    self.textView.frame = CGRectMake(0, kYQPScreenHeight-50-Height_NavBar, kYQPScreenWidth, 50);
    [self.view addSubview:self.textView];

}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self _setNavShadow];
}
-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self _clearNavShadow];
}

#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    MYDynamicCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MYDynamicCommentCell"];
    cell.commentLb.text = @"36氪讯，北京市经济和信息化局近日印发《北京市5G产业发展行动方案（2019年-2022年）》";
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 134;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.001;
}
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    [self.textView resignFirstResponder];
}
#pragma mark - UITableViewDelegate, UITableViewDataSource end

#pragma makr -- lazy
-(QMUITextView *)textView {
    if (!_textView) {
        _textView = [[QMUITextView alloc] init];
        self.textView.font = kSystemMedium(15);
        _textView.backgroundColor = UIColor.whiteColor;
        self.textView.textContainerInset = UIEdgeInsetsMake(14, 12, 14, 12);
        self.textView.placeholder = [NSString stringWithFormat:@"%@~",kYQLS(@"说说你的看法吧")];
        self.textView.textColor = kAPPMainTitleColor;
        self.textView.showsVerticalScrollIndicator = NO;
        self.textView.delegate = self;
        self.textView.returnKeyType = UIReturnKeySend;
    
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kYQPScreenWidth, 1)];
        lineView.backgroundColor = HexColor(0xFAFAFA);
        [self.textView addSubview:lineView];
        
        _keyboardManager = [[QMUIKeyboardManager alloc] initWithDelegate:self];
        // 设置键盘只接受 self.textView 的通知事件，如果当前界面有其他 UIResponder 导致键盘产生通知事件，则不会被接受
        [self.keyboardManager addTargetResponder:self.textView];
    }
    return _textView;
}
#pragma makr -- lazy end
#pragma makr -- QMUITextViewDelegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    if ([text isEqualToString:@"\n"]) {
        
        [self.textView resignFirstResponder];
        return NO;
    }
    return YES;
}

#pragma makr -- QMUITextViewDelegate end

#pragma mark - <QMUIKeyboardManagerDelegate>

- (void)keyboardWillChangeFrameWithUserInfo:(QMUIKeyboardUserInfo *)keyboardUserInfo {
    
    __weak __typeof(self)weakSelf = self;
    [QMUIKeyboardManager handleKeyboardNotificationWithUserInfo:keyboardUserInfo showBlock:^(QMUIKeyboardUserInfo *keyboardUserInfo) {

    } hideBlock:^(QMUIKeyboardUserInfo *keyboardUserInfo) {
        
        [QMUIKeyboardManager animateWithAnimated:YES keyboardUserInfo:keyboardUserInfo animations:^{
        self.textView.frame = CGRectMake(0, kYQPScreenHeight-50-Height_NavBar, kYQPScreenWidth, 50);
        } completion:NULL];
    }];
}
#pragma mark - <QMUIKeyboardManagerDelegate> end
@end
